<!DOCTYPE html>
<html>
<head>
	<meta charset="UTF-8">
	<title>天禾人才</title>
	<meta name="format-detection" content="telephone=no">
	<meta name="viewport" content="minimal-ui=yes,width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<meta name="msapplication-tap-highlight" content="no">
	<meta name="apple-mobile-web-app-capable" content="yes">
	<meta name="apple-mobile-web-app-status-bar-style" content="black">

	<link rel="stylesheet" type="text/css" href="css/mui.min.css" />
	<link rel="stylesheet" type="text/css" href="css/public.css">
	<link rel="stylesheet" type="text/css" href="css/course_details.css">
	
</head>
<body>
	<div class="header">
		<div class="top">
			<div class="sn-nav-back">
				<a href="javascript:;" onclick="javascript:history.back(-1);"><img src="img/back.png"></a>
			</div>
			<div class="sn-nav-title of">课程</div>
		</div>
		
	</div>
	<div class="main">
		<div class="top">
			<div class="header pale-color">
				<img src="img/t_top.jpg">
			</div>
			<div class="title">
				<h3>课程介绍</h3>
			</div>
			<div class="statics clearfix">
				<div class="static-item clearfix">
					<span class="meta">课程标题：</span>
					<span class="meta-value" id="title"></span>
				</div>
				
			</div>

			<div class="statics clearfix">
				<div class="static-item clearfix">
					<span class="meta">课程类别：</span>
					<span class="meta-value" id="type"></span>
				</div>
				
			</div>

			<div class="statics clearfix">
				<div class="static-item clearfix">
					<span class="meta">简介：</span>
					<span class="meta-value" id="desb"></span>
				</div>
			</div>	

			<div class="statics clearfix">
				<div class="static-item clearfix">
					<span class="meta">内容：</span>
					<span class="meta-value">购买后（在我的课程中）查看</span>
				</div>
			</div>	
			
			<div class="statics clearfix">
				<div class="static-item clearfix">
					<span class="meta">联系人：</span>
					<span class="meta-value" id="phone"></span>
				</div>
			</div>	
														
		</div>
	</div>
	<div class="nav clearfix">
		<div class="jiage fl">
			<del id="price"></del>
			<p id="price_discount"></p>
		</div>
		<div class="wybm fl">
			<p><a href="javascript:;" id="btn"></a></p>
		</div>
	</div>
</body>
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script src="js/mui.js"></script>
<script src="js/base.js"></script>

<script type="text/javascript" charset="utf-8">
	mui.init({
		swipeBack: true //启用右滑关闭功能
	});

	var slider = mui("#slider");
	slider.slider({
		interval: 3000
	});
	
	var id="";
	var hash=window.location.hash;
	if(hash==""){
		window.location.href="course_list.html";
	}else{
		if(hash.split("#")[0]==""){
			id=hash.split("#")[1];

			$.ajax({
				url  : "/course/getById",
				type : "post",
				data : {id:id},
 				dataType : "json",
				async : false,
				success : function(data) {
					if (data.code == 0) {
						var entity=data.data;
						$("#title").html(entity.title);
						$("#type").html(entity.type);
						$("#desb").html(entity.desb);
						$("#phone").html(entity.phone);
						if(entity.flag==1){
							$("#price").html("￥"+entity.price);
							$("#price_discount").html("￥"+entity.price_discount);
							$("#btn").html("立即购买");
							$("#btn").addClass("online");
						}else{
							$("#btn").html("立即报名");
							$("#btn").addClass("offline");
						}
						console.log(entity);
					} else {
						
					}
				},
				error : function(jqXHR, textStatus, errorThrown) {
				}
			});	
			
		}else{
			window.location.href="course_list.html";
		}
	}
	
	
	$("#btn").click(function(){
		if($(this).hasClass('online')){
			pay(id);
		}else{
			localStorage.setItem('course_id',id);
			window.location.href="offline.html";
		}
	})
	
     function pay(id){
		var openid=localStorage.getItem("openid");
         $.ajax({
             type: 'POST',
             url: '/wechatPay/jsOrder',
             data: {
            	 	'id':id,
            	 	'openid':openid
              },
             success: function(data){
              console.log(data);
              var appId=data.obj.appId;
              var timeStamp=data.obj.timeStamp;
              var nonceStr=data.obj.nonceStr;
              var packages=data.obj.package;
              var paySign=data.obj.paySign;
              WeixinJSBridge.invoke(
                      'getBrandWCPayRequest', {
                          "appId":appId,                 //公众号名称，由商户传入
                          "timeStamp":timeStamp,         //时间戳，自1970年以来的秒数
                          "nonceStr":nonceStr,           //随机串
                          "package":packages,
                          "signType":"MD5",              //微信签名方式：
                          "paySign":paySign              //微信签名
                      },
                      function(res){
                          WeixinJSBridge.log(res.err_msg);
                          if(res.err_msg == "get_brand_wcpay_request:ok"){
                              alert("购买成功");
                              window.location.href="my_course.html#"+openid;
                          }else if(res.err_msg == "get_brand_wcpay_request:cancel"){
                              alert("购买取消");
                          }else{
                              alert("失败");
                          }
                      }
              );
         } ,
             dataType: "json"});

     }	
</script>


</html>